﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using coffeeshop.coffeeDataSetTableAdapters;

namespace coffeeshop.Models
{
    public class OrderDetail
    {
        private static OrderDetailTableAdapter objOrderDetailAdapter = new OrderDetailTableAdapter();
        public int OrderTableId { get; set; }
        public int ProductId { get; set; }
        public int Quantity { get; set; }
        public int SessionNumber { get; set; }
        public int OrderedBy { get; set; }

        public string ProductName { get; set; }

        public OrderDetail() { }
        public OrderDetail(int v_OrderTableId, int v_SessionNumber)
        {
            OrderTableId = v_OrderTableId;
            SessionNumber = v_SessionNumber;
        }

        public coffeeDataSet.OrderDetailDataTable getOrderDetail(int v_OrderTableId)
        {            
            coffeeDataSet.OrderDetailDataTable objOrderDetailDataTable = new coffeeDataSet.OrderDetailDataTable();
            objOrderDetailDataTable = objOrderDetailAdapter.GetOderDetail(v_OrderTableId);   
            return objOrderDetailDataTable;
        }

        public static int getMaxSessionNumber(int v_OrderTableId)
        {
            coffeeDataSet.OrderDetailDataTable objOrderDetailDataTable = new coffeeDataSet.OrderDetailDataTable();
            return (int)objOrderDetailAdapter.GetMaxSessionNumber(v_OrderTableId);
        }

        public bool insertOrderDetail()
        {
            try
            {
                int intResult = objOrderDetailAdapter.InsertOrder(OrderTableId, ProductId, Quantity, SessionNumber, OrderedBy);
                return intResult == 1;
            }
            catch
            {
                return false;
            }
        }

        public bool updateOrderDetail()
        {
            try
            {
                int intResult = objOrderDetailAdapter.UpdateOrder(OrderTableId, ProductId, SessionNumber);
                return intResult == 1;
            }
            catch
            {
                return false;
            }
        }                
        
    }
}
